$("#editinfo").click(function(){
   var edit1 = layer.open({
		type: 1,
		scrollbar: false,
		fixed:true,
		area: '500px,530px',
		title: '编辑个人信息',
		content: $("#editinfobox")	
	})
});
$(".j-cancel").click(function(){
	layer.closeAll(); 
})
$.get("userWeb/getUserInfo",function(res){
	if(!res.content){
		return;
	};
	$("#emailID").text(res.content.email);
	$("#name").val(res.content.name);
	$("input :radio").eq(0).val(res.content.sex);
	if(res.content.sex=="男"){
		$("input[name='sex']").eq(0).prop("checked",true); 
	}else if(res.content.sex=="女"){
		$("input[name='sex']").eq(1).prop("checked",true); 
	}
	$("#education").val(res.content.education);
	$("#major").val(res.content.major);
	$("#signature").val(res.content.signature);
	var l = $("#signature").val().length;
	l = 50-l;
	if (l<=50){
		$("#zs").html("还可以输入"+l+"个字");
	}
	_init_area();
	setTimeout(function(){
		$("select[name='s_province']").val(res.content.province);
		change(1);
		setTimeout(function(){
			$("select[name='s_city']").val(res.content.city);
			change(2);
				setTimeout(function(){
					$("select[name='s_county']").val(res.content.area);
				}, 100);
		}, 100);
	}, 100);
})
$("#signature").keyup(function(){
	var l = $("#signature").val().length;
	l = 50-l;
	if (l<=50){
		$("#zs").html("还可以输入"+l+"个字");
	}
})
$(".j-sure").click(function(){
	var nickname = $("#name").val();
	var sex = $("input[name='sex']:checked").val(); 
	var education = $("#education").val();
	if($("#s_province").val()){
		var province = $("#s_province").val();
	}else{
		var province = "";
	};
	if($("#s_city").val()){
		var city = $("#s_city").val();
	}else{
		var city = "";
	};
	if($("#s_county").val()){
		var area = $("#s_county").val();
	}else{
		var area = "";
	};
	var major = $("#major").val();
	
	
	var signature = $("#signature").val();
	var data = {
		"userInfo.nickname":nickname,
		"userInfo.sex":sex,
		"userInfo.education":education,
		"userInfo.major":major,
		"userInfo.province":province,
		"userInfo.city":city,
		"userInfo.area":area,
		"userInfo.signature":signature
	};
	$.post("userWeb/updateUserInfo",data,function(res){
		console.log(res);
		if(res.code == "0"){
			$("#u_name").text(nickname);
			$("#u_major").text(major);
			$("#u_signature").text(signature);
			layer.closeAll('page'); 
			layer.msg("修改成功",{time:1500});
		}else if(res.code == "1"){
			layer.msg("网络不给力哦，请再试一次",{time:1500});
		}
			
	})
})


